#include <iostream>
#include <cstring>

void reversal(char str[], int lo, int hi)
{
    for (int i = lo, j = hi; i < j; ++i, --j) {
        str[i] = str[i] ^ str[j];
        str[j] = str[i] ^ str[j];
        str[i] = str[i] ^ str[j];
    }
}

void rotate(char str[], int k)
{
    int len = strlen(str);
    k %= len;
    reversal(str, 0, k - 1);
    reversal(str, k, len - 1);
    reversal(str, 0, len - 1);
}

int main(int argc, const char *argv[])
{
    char str[] = "abcdefgh";
    std::cout << str << std::endl;
    rotate(str, 2);
    std::cout << str << std::endl;
    return 0;
}
